import Toast from '@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fileList: [],
    nickname: '',
    types: '',
    customStyle: "background:#02A8A6;border:none;border-radius:12rpx;"
  },
  deleteFull(event) {
    console.log(event.detail.index);
    let that = this
    let list = that.data.fileList;
    list.splice(event.detail.index, 1);
    that.setData({
      fileList: list
    })
  },
  afterRead(event) {
    const {
      file
    } = event.detail;
    console.log(file.url);
    const {
      fileList = []
    } = this.data;
    fileList.push({
      ...file,
      url: file.url
    });
    this.setData({
      fileList
    });
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    // wx.uploadFile({
    //   url: 'https://example.weixin.qq.com/upload', // 仅为示例，非真实的接口地址
    //   filePath: file.url,
    //   name: 'file',
    //   formData: { user: 'test' },
    //   success(res) {
    //     // 上传完成需要更新 fileList
    //     const { fileList = [] } = this.data;
    //     fileList.push({ ...file, url: res.data });
    //     this.setData({ fileList });
    //   },
    // });
  },
  actInput(e) {
    let that = this
    that.setData({
      nickname: e.detail
    })
  },
  save() {
    let that = this
    Toast({
      type: 'success',
      message: '提交成功',
      onClose: () => {
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2]; //上一个页面
        let object = {
          nickname: that.data.nickname,
          fileList:that.data.fileList
        }
        prevPage.onShow(object);
        wx.navigateBack({
          data: 1
        })
      },
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    let that = this
    let list = that.data.fileList
    if(options.avatarurl!=''){
      list.push({
        url: options.avatarurl
      })
    }else{
      list = []
    }
    that.setData({
      nickname: options.nickname,
      types: options.types,
      fileList:list
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})